﻿using System;

namespace RRRSRoguelike.Helpers.Visualizer
{
	public struct DungeonSquare
	{
		public string character;
		public ConsoleColor color;
		public ConsoleColor background;
	}
	/// <summary>
	/// Perserves the layers of the dungeon as the player traverses the layers.
	/// Gathers squares of the dungeon and updates necessary squares prior to 
	/// rendering the current view of the layer to the screen.
	/// </summary>
	public class Layer
	{
		//for drawing dungeon
		public DungeonSquare[,] DungeonSquares;

		//for preventing redrawing
		public DungeonSquare[,] OldDungeonSquares;

		public Layer()
		{
			DungeonSquares = new DungeonSquare[Constants.DungeonWidth, Constants.DungeonHeight];

			OldDungeonSquares = new DungeonSquare[Constants.DungeonWidth, Constants.DungeonHeight];

		}

		public Layer(int width, int height)
		{
			DungeonSquares = new DungeonSquare[width, height];

			OldDungeonSquares = new DungeonSquare[width, height];

		}

		public bool HasChanged(int x, int y)
		{
			return DungeonSquares[x, y].character != OldDungeonSquares[x, y].character ||
			       DungeonSquares[x, y].color != OldDungeonSquares[x, y].color;
		}

		public void ClearOldSquares()
		{
			OldDungeonSquares = new DungeonSquare[Constants.DungeonWidth, Constants.DungeonHeight];
		}

		public void RecordOldSquares()
		{
			OldDungeonSquares = (DungeonSquare[,])DungeonSquares.Clone();
		}
	}
}
